package com.ibeeking.found.upms.b.rest.controller.v1.feign;

import com.ibeeking.found.upms.b.rest.service.IShopUserService;
import com.ibeeking.found.common.constants.HeaderNounConstant;
import com.ibeeking.found.common.db.annotation.IgnoreDS;
import com.ibeeking.found.upms.api.common.dto.TenantUserDTO;
import com.ibeeking.found.upms.api.common.param.ShopAdminInitParam;
import com.ibeeking.found.upms.service.common.dos.ShopUserDO;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import com.ibeeking.nematos.utils.data.Collections3;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ShopUserController控制器
 * @Description 商户用户管理
 * @Author ibeeking
 * @Date 2020-12-02 15:29
 **/
@RestController
@RequestMapping("/b/shop/feign/v1")
public class ShopFeignController {

    @Resource
    private IShopUserService shopUserServiceImpl;

    @PostMapping(value = "/initShopAdmin")
    public Boolean initShopAdmin(@RequestHeader(HeaderNounConstant.TENANT_ID) String tenantId, @Validated @RequestBody ShopAdminInitParam param) {
        return shopUserServiceImpl.initShopAdmin(Integer.valueOf(tenantId), param);
    }

    /**
     * 根据手机号查询商户用户信息
     *
     * @param mobile
     * @return
     */
    @IgnoreDS
    @PostMapping(value = "/queryByMobile/{mobile}")
    public TenantUserDTO queryShopUserByMobile(@PathVariable("mobile") String mobile) {
        List<ShopUserDO> shopUserDOS = shopUserServiceImpl.queryByMobile(mobile);
        if (Collections3.isEmpty(shopUserDOS)) {
            return null;
        }
        return BeanUtil.convertBean(shopUserDOS.get(0), TenantUserDTO.class);
    }
}
